home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / comms / other / gs_hint / hint.amirx < prev   
Text File  |  1999-05-17  |  9KB  |  323 lines

  1. /* Hint.amirx v1.1
  2. //
  3. //  --- DEDICATED TO PEACE --- NO MORE WAR ---
  4. //
  5. //  copyright (c) 1998-1999 George Stagakis (gallant@pathfinder.gr)
  6. //
  7. //  changes in v1.1:
  8. //    · Added 'bonus round' (optional) Every once in a while the game starts
  9. //    in 'bonus round' mode. The score added to the winner is randomly
  10. //    more than 3 and less than 7 points instead of a single point.
  11. //    Just to increase adrenaline :P
  12. //    · Added 'winning score' (optional) When a player reaches this score,
  13. //    he wins the game and the score board is cleared for a new start.
  14. //    · Added 'top players' (optional) Only shows best top n players in
  15. //    the score board, but the whole score board remains in memory.
  16. //
  17. //  description:
  18. //    Multiplayer hint/scramble game (v1.1) for AmIRC.
  19. //
  20. //    The scrambler gives out an answer and a question. The answer
  21. //    is displayed scrambled to the players and the question is
  22. //    clear. The first one to find the answer receives a point.
  23. //    For entering the game, the player just needs to answer a question
  24. //    and win a point. That puts him in the score board and in the game.
  25. //    No other operations are required. The score board clears whenever
  26. //    the scrambler wants it, or when 'timeout loss' or 'score melting'
  27. //    throws away all of the players, or when a player reaches
  28. //    'winning score' (wins the game).
  29. //
  30. //    The game starts and ends when a player answers correctly. However, the
  31. //    score board remains in memory. There are also a few tricks to make it
  32. //    more interesting and more active like 'timeouts', 'score melting' and
  33. //    'bonus round'. Also an ability to show only the best players in the
  34. //    score board instead of all of them.
  35. //    Public displays are very few making it more compact and fun without
  36. //    flooding the channels.
  37. //
  38. //  usage:
  39. //    Put Hint.amirx in AmIRC:Rexx/
  40. //    /ALIAS Hint /RX Hint
  41. //
  42. //    /HINT answer : question [-n]
  43. //    answer: The answer to be displayed scrambled. It can contain spaces
  44. //            and such.
  45. //    question: The question to be displayed clear. Put anything you want.
  46. //    -n: Game starts normally but the score board is cleared completely.
  47. //
  48. //  demo:
  49. //    /HINT Rolling Stones : Famous rock band.
  50. //       <nick> | [unscramble]: oRnglil esSnto
  51. //       <nick> | [hint]: Famous rock band.
  52. //        <bbb> | rolling stone
  53. //        <ccc> | roling stones
  54. //        <aaa> | rolling stones
  55. //       <nick> | Correct aaa: Rolling Stones
  56. //       <nick> | [score]: [aaa - 7] [bbb - 6] [ccc - 5] [ddd - 3] [eee - 1]
  57. //
  58. //  notes:
  59. //    Freely distributable
  60. //    Requires rexxtricks.library 38.6 or greatest
  61. //    Options editable in script
  62. //    E-mails welcome
  63. //    Not sure if it works :P Try everything and then bug me
  64. //
  65. //  history:
  66. //    (06-Oct-98) 0.9 First version
  67. //    (05-May-99) 1.0 First public release
  68. //    (08-May-99) 1.1 Added 'bonus round', 'winning score' and 'top players'
  69. //
  70. */
  71.  
  72. /* traps */
  73. options results;signal on syntax;signal on break_c;signal on halt
  74.  
  75. /* options */
  76. winscore = 20   /* winning score. when a player reaches this, game finishes
  77.                    and scoreboard is cleared (0=Off) */
  78. topplayers = 10 /* only show the best n players in the scoreboard (0=Off) */
  79. timeout = 1     /* times out game after 'timelimit' seconds (0=No,1=Yes) */
  80. timelimit = 30  /* seconds to timeout (if active) */
  81. timeloss = 3    /* points every player loses after timeout (if active) */
  82. meltscore = 1   /* decrease 'meltpoints' points on every round on players
  83.                    that haven't played for 'meltrounds' rounds (0=No,1=Yes) */
  84. meltpoints = 1  /* points to decrease on meltscore (if active) */
  85. meltrounds = 7  /* rounds to meltscore (if active) */
  86. bonusround = 1  /* bonus rounds. score +3 to +7 instead of +1 sometimes */
  87.  
  88. debug = 0
  89. script = 'Hint'
  90.  
  91. /* libraries */
  92. if ~openlib('rexxtricks.library',10) then exit
  93.  
  94. /* setup */
  95. /* () */
  96.  
  97. /* program */
  98. parse arg text
  99.  
  100. if text = '' then cechox('Usage: /HINT answer : question [-n]')
  101. if word(text,words(text)) = '-n' then do
  102.     call setclip('hint_score')
  103.     text = delword(text,words(text))
  104. end
  105. otext = text
  106. ctext = upper(otext)
  107.  
  108. parse var text ans' : 'que
  109.  
  110. nans = ''
  111. do i=1 to words(ans)
  112.     nans = nans' 'scramble(word(ans,i))
  113. end
  114. nans = strip(nans)
  115.  
  116. 'ISCONNECTED'
  117. if rc = 5 then cechox("Not connected to a server, can't run Hint.")
  118.  
  119. channel = getchannel()
  120.  
  121. cnt = 0
  122.  
  123. uscore = getclip('hint_score')
  124. if uscore ~= '' then do
  125.     do i=1 to words(uscore) by 3
  126.         cnt = cnt + 1
  127.         users.cnt = word(uscore,i)' 'word(uscore,i+1)' 'word(uscore,i+2)
  128.     end
  129. end
  130.  
  131. bo = bold('[')
  132. bc = bold(']')
  133.  
  134. scoreadd = 1
  135. bonustext = ''
  136. if rxtr_rand(1,6) = 6 & bonusround = 1 then do
  137.     scoreadd = rxtr_rand(3,7);bonustext = 'BONUS ROUND 'bold('+'scoreadd)' - '
  138. end
  139. csend('/MSG 'channel' 'bonustext||bo||underline('unscramble')||bc': 'nans)
  140. csend('/MSG 'channel' 'bo||underline('hint')||bc': 'que)
  141.  
  142. call time('r')
  143. do forever
  144.     'GETLINE'
  145.     utext = upper(substr(line.rest,2))
  146.     parse var line.prefix nick'!'.
  147.  
  148.     if utext = upper(ans) then do
  149.         csend('/MSG 'channel' Correct 'nick': 'ans)
  150.         npos = chknick(nick)
  151.         if npos = 0 then do
  152.             cnt = cnt + 1
  153.             score = scoreadd
  154.             users.cnt = nick' 'score' 0'
  155.         end
  156.         else do
  157.             parse var users.npos .' 'score' 'age
  158.             score = score + scoreadd
  159.             age = 0
  160.             users.npos = nick' 'score' 'age
  161.         end
  162.         users.0 = cnt
  163.         call rxtr_qsort('users',,'NUM',2)
  164.         ustr = ''
  165.         uscore = ''
  166.         do i=cnt to 1 by -1
  167.             parse var users.i u1' 'u2' 'u3
  168.             u3 = u3 + 1
  169.             if u3 > meltrounds & meltscore = 1 then u2 = u2 - meltpoints
  170.             if u2 > 0 then do
  171.                 users.i = u1' 'u2' 'u3
  172.                 ustr = ustr' 'bo||word(users.i,1)' - 'word(users.i,2)||bc
  173.                 uscore = uscore' 'users.i
  174.             end
  175.         end
  176.         ustr = strip(ustr)
  177.         if (words(ustr) > topplayers*3) & (topplayers > 0) then ustr = subword(ustr,1,topplayers*3)
  178.         uscore = strip(uscore)
  179.         csend('/MSG 'channel' 'bonustext||bo||underline('score')||bc': 'ustr)
  180.         call setclip('hint_score',uscore)
  181.         if (score >= winscore) & (winscore > 0) then do
  182.             csend('/MSG 'channel' 'bo'*'bc' WINNER 'bo'*'bc' 'bold(nick)' wins the game!')
  183.             call setclip('hint_score')
  184.         end
  185.         exit
  186.     end
  187.  
  188.     if time(e) > timelimit & timeout = 1 then do
  189.         csend('/MSG 'channel' Too late! Correct: 'ans)
  190.         users.0 = cnt
  191.         call rxtr_qsort('users',,'NUM',2)
  192.         ustr = ''
  193.         uscore = ''
  194.         do i=cnt to 1 by -1
  195.             parse var users.i u1' 'u2' 'u3
  196.             u2 = u2 - timeloss
  197.             u3 = u3 + 1
  198.             if u3 > meltrounds & meltscore = 1 then u2 = u2 - meltpoints
  199.             if u2 > 0 then do
  200.                 users.i = u1' 'u2' 'u3
  201.                 ustr = ustr' 'bo||word(users.i,1)' - 'word(users.i,2)||bc
  202.                 uscore = uscore' 'users.i
  203.             end
  204.             ustr = strip(ustr)
  205.             uscore = strip(uscore)
  206.         end
  207.         if (words(ustr) > topplayers*3) & (topplayers > 0) then ustr = subword(ustr,1,topplayers*3)
  208.         if ustr = '' then ustr = 'no scorer'
  209.         csend('/MSG 'channel' 'bo||underline('score')||bc': (losing 'timeloss' points) 'ustr)
  210.         call setclip('hint_score',uscore)
  211.         exit
  212.     end
  213.  
  214. end
  215.  
  216. exit
  217.  
  218. /* custom functions */
  219. scramble: procedure
  220.     parse arg text
  221.     stext = text
  222.     if length(text) > 1 then do until stext ~= text
  223.         do 3
  224.         otext = text
  225.         if length(text) > 1 then do until otext ~= text
  226.             lng = length(text)+3
  227.             do i=1 to length(text)
  228.                 rnd = rxtr_rand(1,lng)
  229.                 rnd2 = rxtr_rand(1,lng)
  230.                 a = substr(text,rnd,1)
  231.                 text = delstr(text,rnd,1)
  232.                 text = insert(a,text,rnd2-1)
  233.             end
  234.             text = space(text,,0)
  235.         end
  236.         end
  237.     end
  238. return text
  239.  
  240. chknick: procedure expose users. cnt
  241.     parse arg nick
  242.     do i=1 to cnt
  243.         if upper(nick) = upper(word(users.i,1)) then return i
  244.     end
  245. return 0
  246.  
  247. wait:  /* functional flood protection */
  248. do 2000;end
  249. return 1
  250.  
  251. lower:
  252. return translate(arg(1),xrange('a','z'),xrange('A','Z'))
  253.  
  254. csend:
  255. cdo(arg(1))
  256. wait()
  257. return 1
  258.  
  259. cechox:
  260. cecho(arg(1))
  261. exit
  262.  
  263. /* global functions */
  264. chop:
  265.     cdo('/OP' arg(1))
  266. return 0
  267.  
  268. cmsg:
  269.     cdo('/NOTICE' arg(1))
  270. return 0
  271.  
  272. cdo:
  273. if ~debug then 'SAY' arg(1)
  274. else cecho(arg(1))
  275. return 0
  276.  
  277. craw:
  278. if ~debug then 'RAW' arg(1)
  279. else cecho(arg(1))
  280. return 0
  281.  
  282. cecho:
  283. 'echo P='d2c(27)'b«'script'» TEXT='arg(1)
  284. return 0
  285.  
  286. ciecho:
  287. 'echo P='d2c(27)'b«'script'» C=3 TEXT='arg(1)
  288. return 0
  289.  
  290. getmynick:
  291.     'GETMYNICK'
  292. return result
  293.  
  294. getusers:
  295.     'GETUSERS CHANNEL='arg(1)
  296. return result
  297.  
  298. getchannel:
  299.     'GETCHANNEL'
  300. return result
  301.  
  302. openlib: procedure
  303.